package boogui.seat;

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class MemberSeat extends JFrame {

	private JPanel contentPane;
	
	private JCheckBox[] seats = new JCheckBox[200];

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MemberSeat frame = new MemberSeat();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MemberSeat() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1100, 800);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(40, 0));
		setContentPane(contentPane);
		setResizable(false);
		
		JPanel panel_24 = new JPanel();
		contentPane.add(panel_24, BorderLayout.SOUTH);
		panel_24.setLayout(new BoxLayout(panel_24, BoxLayout.Y_AXIS));
		
		JPanel panel_25 = new JPanel();
		panel_24.add(panel_25);
		
		JButton btn = new JButton("예매하기");
		
		panel_25.add(btn);
		
		JPanel panel_5 = new JPanel();
		panel_5.setAlignmentX(Component.LEFT_ALIGNMENT);
		contentPane.add(panel_5, BorderLayout.CENTER);
		panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.X_AXIS));
		
		JPanel panel_7 = new JPanel();
		panel_5.add(panel_7);
		panel_7.setLayout(new BoxLayout(panel_7, BoxLayout.X_AXIS));
		
		JPanel panel_1 = new JPanel();
		
		
		panel_7.add(panel_1);
		panel_1.setLayout(new GridLayout(10, 5, 8, 5));
		
		JPanel panel_15 = new JPanel();
		panel_7.add(panel_15);
		
		JLabel Newlbl_1 = new JLabel("     ");
		panel_15.add(Newlbl_1);
		
		JPanel panel_2 = new JPanel();
		panel_5.add(panel_2);
		panel_2.setLayout(new GridLayout(10, 10, 18, 5));
		
		JPanel panel_14 = new JPanel();
		panel_5.add(panel_14);
		panel_14.setLayout(new BoxLayout(panel_14, BoxLayout.X_AXIS));
		
		JPanel panel_16 = new JPanel();
		panel_14.add(panel_16);
		
		JLabel Newlbl_2 = new JLabel("   ");
		panel_16.add(Newlbl_2);
		JPanel panel_3 = new JPanel();
		panel_14.add(panel_3);
		panel_3.setLayout(new GridLayout(10, 5, 8, 5));
		
		
		JPanel panel_6 = new JPanel();
		contentPane.add(panel_6, BorderLayout.WEST);
		panel_6.setLayout(new GridLayout(10, 1, 0, 13));
		
		JPanel panel_8 = new JPanel();
		contentPane.add(panel_8, BorderLayout.NORTH);
		panel_8.setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		panel_8.add(panel, BorderLayout.NORTH);
		
		JLabel lblScreen = new JLabel("Screen");
		lblScreen.setFont(new Font("굴림", Font.PLAIN, 30));
		panel.add(lblScreen);
		
		JPanel panel_9 = new JPanel();
		panel_8.add(panel_9, BorderLayout.WEST);
		panel_9.setLayout(new BoxLayout(panel_9, BoxLayout.X_AXIS));
		
		JPanel panel_12 = new JPanel();
		panel_9.add(panel_12);
		panel_12.setLayout(new BoxLayout(panel_12, BoxLayout.X_AXIS));
		
		JLabel Newlbl = new JLabel("                ");
		panel_12.add(Newlbl);
		
		JPanel panel_17 = new JPanel();
		panel_9.add(panel_17);
		panel_17.setLayout(new BoxLayout(panel_17, BoxLayout.X_AXIS));
		
		JPanel panel_13 = new JPanel();
		panel_17.add(panel_13);
		panel_13.setLayout(new GridLayout(1, 5, 35, 0));
		
		JPanel panel_18 = new JPanel();
		panel_17.add(panel_18);
		
		JLabel Newlbl_3 = new JLabel("                 ");
		panel_18.add(Newlbl_3);
		
		JPanel panel_21 = new JPanel();
		panel_8.add(panel_21, BorderLayout.CENTER);
		
		JPanel panel_10 = new JPanel();
		panel_21.add(panel_10);
		panel_10.setLayout(new GridLayout(1, 4, 36, 0));
		
		JPanel panel_23 = new JPanel();
		panel_21.add(panel_23);
		
		JLabel Newlbl_5 = new JLabel("     ");
		panel_23.add(Newlbl_5);
		
		JPanel panel_22 = new JPanel();
		panel_21.add(panel_22);
		panel_22.setLayout(new GridLayout(1, 6, 30, 0));
		
		JPanel panel_19 = new JPanel();
		panel_8.add(panel_19, BorderLayout.EAST);
		
		JPanel panel_20 = new JPanel();
		panel_19.add(panel_20);
		
		JLabel Newlbl_4 = new JLabel("");
		panel_20.add(Newlbl_4);
		
		JPanel panel_11 = new JPanel();
		
		panel_19.add(panel_11);
		FlowLayout flowLayout = (FlowLayout) panel_11.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		flowLayout.setHgap(25);
		
		for(int i = 1; i <= 5; i++){
			
			panel_13.add(new JLabel(i+""));
		}
		for(int i = 6; i <= 9; i++){
			panel_10.add(new JLabel(i+""));
		}
		for(int i = 10; i <= 15; i++){
			panel_22.add(new JLabel(i+""));
		}
		for(int i = 16; i <= 20; i++){
			panel_11.add(new JLabel(i+""));
		}
		
		for(int i = 65; i <= 74; i++){
			panel_6.add(new JLabel((char)i+""));
		}
		
		//체크박스
		
		int chbox[] = new int[200];
		for(int i = 0; i < 50; i++){
			seats[i] = new JCheckBox("");
			panel_1.add(seats[i]);
			if ( i / 5 == 0 ) System.out.println();
			
		}
		
		for(int i = 50; i < 150; i++){
			seats[i] = new JCheckBox("");
			panel_2.add(seats[i]);
			if ( i / 10 == 0 ) System.out.println();
		}
		
		for(int i = 150; i < 200; i++){
			seats[i] = new JCheckBox("");
			panel_3.add(seats[i]);
			if ( i / 5 == 0 ) System.out.println();
		}
		
		char ac = 0;
		
		btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				for(int i = 0; i < 200; ++i){
					
					System.out.println(seats[i].isSelected());
					if(seats[i].isSelected() == true){
						
						seats[i].setEnabled(false);
						
						Connection conn = null;
						PreparedStatement pstmt = null;
						ResultSet rs = null;
						boolean result = false;

						try {
							conn = bdao.openDatabase();
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, val);
							rs = pstmt.executeQuery();

							if (rs.next()) {
								result = true; // 값이 있으면 true 중복
							} else {
								result = false; // 값이 없으면 false 중복아님
							}
						} catch (Exception ex) {
							ex.printStackTrace();
						} finally {
							bdao.closeDatabase(conn, pstmt, rs);
						}
						return result;
						
						
					}
					
				}
				
			};
		
		});
	}
}